#include<iostream>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<sys/types.h>


extern char**environ;

int main()
{
  pid_t id=fork();
  if(id==0)
  {
    printf("我是子进程，pid：%d,ppid:%d,将要程序替换\n",getpid(),getppid());
    //execl("./test","test",NULL);
    execlp("ls","ls","-l","-a",NULL);
   // char* const env_[]={(char*)"MYPATH=byld",NULL};
   // execle("./mycmd","mycmd",NULL,env_);
  // execle("./mycmd","mycmd",NULL,environ);
  }
  
  else
  {
    int status=0;
    int ret = waitpid(id,&status,0);
    if(ret==id)
    {
      sleep(2);
      printf("我是父进程,pid:%d,ppid:%d\n",getpid(),getppid());
    }
  }
  return 0;
}
